//
//  SYComposeBtn.swift
//  SYWeibo
//
//  Created by Saya on 16/4/15.
//  Copyright © 2016年 黄金果. All rights reserved.
//

import UIKit

//class SYComposeBtn: UIButton {
//    lazy var iconImg:UIImageView = UIImageView()
//    lazy var textLb = UILabel(text: "", font: 14, textColor: UIColor.darkGrayColor())
//    var model:SYComposeModel?
//    
//    override init(frame: CGRect) {
//        super.init(frame: frame)
//        addSubview(iconImg)
//        addSubview(textLb)
//    }
//
//    required init?(coder aDecoder: NSCoder) {
//        fatalError("init(coder:) has not been implemented")
//    }
//    
//    convenience init(iconImage:UIImage,title:String,frame:CGRect,model:SYComposeModel) {
//        self.init(frame:frame)
//        iconImg.image = iconImage
//        textLb.text = title
//        self.frame = frame
//        self.model = model
//    }
//    
//    override func layoutSubviews() {
//        super.layoutSubviews()
//        let width:CGFloat = self.frame.size.width
//        let height:CGFloat = self.frame.size.height
//        iconImg.frame = CGRect(x: 0, y: 0, width: width, height: height*0.7)
//        textLb.frame = CGRect(x: 0, y: height*0.7, width: width, height: height*0.3)
//    }
//
//}
//使用上面的方法创建btn,给按钮添加动画的时候,缩放动画不会从中间开始执行,为什么呢


private let btnWidth:CGFloat = 80
class SYComposeBtn: UIButton{
    var model:SYComposeModel?{
        didSet{
            setTitle(model!.title ?? "", forState: .Normal)
            setImage(UIImage(named: model!.icon ?? "")!, forState: .Normal)
            titleLabel?.textAlignment = .Center
            titleLabel?.textColor = UIColor.darkGrayColor()
//            self.buttonType = UIButtonType.Custom
        }
    }
//    convenience init(iconImage:UIImage,title:String,model:SYComposeModel){
//        self.init()
//
//        self.model = model
//        
//    }
    
    
    
    
    override func titleRectForContentRect(contentRect: CGRect) -> CGRect {
        return CGRect(x: 0, y: btnWidth, width: btnWidth, height: self.frame.size.height - btnWidth)
    }
    
    override func imageRectForContentRect(contentRect: CGRect) -> CGRect {
        return CGRect(x: 0, y: 0, width: btnWidth, height: btnWidth)
    }
}
